package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;


@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 发送手机短信验证码
     * @param user
     * @return
     */
    @PostMapping("/sendMsg")
    public R<String> sendMsg(@RequestBody User user, HttpSession httpSession){
        R<String> r = userService.sendMsg(user, httpSession);
        return r;
    }

    /**
     * 移动端用户登录
     * @param map
     * @param httpSession
     * @return
     */
    @PostMapping("/login")
    public R<User> login(@RequestBody Map map,HttpSession httpSession) {
        log.info(map.toString());
        R<User> r = userService.login(map, httpSession);
        return r;
    }

    /**
     * 移动端用户退出
     * @param res
     * @return
     */
    @PostMapping("/loginout")
    public R<String> loginOut(HttpServletRequest res){
        log.info("退出");
        R<String> r = userService.loginOut(res);
        return r;
    }
}
